# _*_ coding: utf-8 _*_
from odoo import models, fields, api


class SaleOrderLine(models.Model):
    _inherit = "account.invoice.line"

    product_customer_name = fields.Char(string=u'客户产品名称', compute='_compute_product_customer_name')
    product_customer_code = fields.Char(string=u'客户产品编号', compute='_compute_product_customer_name')

    @api.depends("product_id", "partner_id")
    def _compute_product_customer_name(self):
        ProductCustomerName = self.env["product.customer.name"]
        for line in self:
            customer_name = ProductCustomerName.search([("product_id", "=", line.product_id.id), ('partner_id', '=', line.partner_id.id)])
            if customer_name:
                if not line.product_customer_name:
                    line.product_customer_name = customer_name.product_customer_name
                if not line.product_customer_code:
                    line.product_customer_code = customer_name.product_customer_code
